<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* 
*/
class Login extends D_Controller
{
	
	public function __construct()
	{
		parent::__construct();
		
		$this->load->model('m_customer');
		$this->load->helper('form');
	}

	public function index()
	{
		$this->load->view_tpls('v_login');
	}
	
	public function custlogin(){
	    $cust = $this->m_customer->validate_customer($_POST['email'],$_POST['password']);
	    
	    if(!$cust){
	        echo 'error email or password!';
	    }else{
	        $this->session->set_userdata('customer_id',$cust['customer_id']);
	        $this->session->set_userdata('customer_name',$cust['customer_name']);
	        
	        if($this->input->server('HTTP_REFERER')){
	            redirect($this->input->server('HTTP_REFERER'));
	        }
	    }
	}
	
	public function register(){
	    $data = $_POST;
	    
	    $cust_id = $this->m_customer->insert($data);
	    
	    if(!$cust_id){
	        echo 'failed...';
	    }else{
	        echo 'register success...';
	    }
	}
}

/* End of file login.php */
/* Location: ./application/controllers/login.php */